/**
 * 
 */
package com.pos.modules.cashier;

import android.content.ContentValues;
import android.content.Intent;
import android.content.res.Configuration;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.basewin.aidl.OnPrinterListener;
import com.basewin.services.ServiceManager;
import com.pos.BaseActivity;
import com.pos.R;
import com.pos.YourApplication;
import com.pos.modules.bean.UserBean;
import com.pos.modules.cashier.adapter.AccountGoodsListAdapter;
import com.pos.modules.cashier.bean.AccountGoodsBean;
import com.pos.net.base.Request.Method;
import com.pos.net.netparam.NetParams;
import com.pos.net.netparam.RequestUrls;
import com.pos.net.request.interfa.BaseRequestListener;
import com.pos.net.request.interfa.JsonRequestListener;
import com.pos.set.AppSet;
import com.pos.toolbox.FinancialUtils;
import com.pos.toolbox.Tools;
import com.pos.toolbox.file.FilesManager;
import com.pos.widgets.ActionBarManager;
import com.pos.widgets.ListViewForScrollView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:收银台-结算
 * @author cai
 * @time:2017年10月15日下午11:40:02
 */
public class AccountActivity extends BaseActivity implements OnClickListener {
	private String goods, orderId, memberCode, memberPayToken, memberBalance, levelName, memberScore;
	private long totalPrice, finalPrice, discountPrice;
	private TextView button_back;
	private RelativeLayout  button_weixin, button_zhifubao, button_yizhifu, button_shuaka;
	private ListViewForScrollView listView;
	private List<AccountGoodsBean> goodsList = new ArrayList<>();
	private AccountGoodsListAdapter adapter;
	private Gson gson;
	private TextView text_total, text_totalPrice, text_finalPrice, text_discountPrice, text_memberCode, text_levelName,
			text_memberBalance, text_memberScore;
	private LinearLayout linear_member;
	private int payType = 1;
	private UserBean userBean;
	private String merId, tstTypeId;
	private String sn= android.os.Build.SERIAL;
    JSONObject printJson = new JSONObject();
   private  PrinterListener printer_callback = new PrinterListener();
	/**
	 * 是否为快速收银（从快速收银界面跳转过来，界面布局不一样）
	 */

	/*
	* 　　　　POS 签购单\n　　　　　（消费单）\n商户名称：自坚零售\n交易号: 0001-180505093320-0060\n交易时间:2018-05-05 09:33:20\n应收：0.01\n实收：0.01\n折让: 0.00\n支付方式：现金支付\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：自坚零售\n交易号: 0001-180505093320-0060\n交易时间:2018-05-05 09:33:20\n应收：0.01\n实收：0.01\n折让: 0.00\n支付方式：现金支付\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n
	*
	* */
	private boolean isFastCashier = false;
	private String goodinfo="";

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}
    public class PrinterListener implements OnPrinterListener {

        @Override
        public void onStart() {
            // TODO 打印开始
            // Print start
            // Log.d(TAG, getStr(R.string.print_start));
            // sb.append(getStr(R.string.print_start) + "\n");
            // showText(sb);
            Log.e(Tag, "PrinterListener onStart");
        }

        @Override
        public void onFinish() {
            // TODO 打印结束
            // End of the print
            // Log.d(TAG, getStr(R.string.print_end));
            // sb.append(getStr(R.string.print_end) + "\n");
            // showText(sb);
            Log.e(Tag, "PrinterListener onFinish");

        }

        @Override
        public void onError(int errorCode, String detail) {
            // TODO 打印出错
            // print error
            // Log.d(TAG, getStr(R.string.print_error) + " errorcode = " +
            // errorCode + " detail = " + detail);
            // sb.append(getStr(R.string.print_error) + errorCode + " detail = "
            // + detail + "\n");
            // showText(sb);
            Log.e(Tag, "PrinterListener onError " + detail);

        }
    };
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		Log.e("TAG", "onActivityResult: "+requestCode );
		if (requestCode == 1) {
			if (resultCode == RESULT_OK) {
				setResult(RESULT_OK);
				finish();
			}
		}
		if (requestCode == 0) {
			if (resultCode == RESULT_OK) {
				setResult(RESULT_OK);
				finish();
			}
		} else if (requestCode == 11) {
			setResult(RESULT_OK);
			finish();
		} else if (requestCode == 100) {
			if (resultCode == RESULT_OK) {
				if (data != null) {
					String dealData = data.getStringExtra(PayContacts.RETURN_DATA);
					if (!TextUtils.isEmpty(dealData)) {
						JSONObject result;
						try {
							result = new JSONObject(dealData);
							String payBillNumber = result.optString("voucherNo");
							long payAmount = result.optLong("amount", 0);
							String dealTime = result.optString("dealTime");
							String secondPayNumber = "";
							if (payType != 4) {
								secondPayNumber = result.optString(PayContacts.SERVERAUDITNUMBER);
								ContentValues values = new ContentValues();
								values.put("id",orderId);
								values.put("payStatus","0");
								values.put("payMethod",payType+"");
								values.put("payBillNumber",payBillNumber);
								values.put("payDate",dealTime);
								values.put("payAmount",payAmount);
								values.put("cashAmount","0");
								values.put("cashChange","0");
								values.put("memberPayToken",memberPayToken);
								values.put("secondPayNumber",secondPayNumber);
								values.put("merCode","");
								values.put("merName","");
								values.put("termCode","");
								values.put("bankName","");
								values.put("bankCard","");
								values.put("bankCardExpired","");

								values.put("authorCode","");
								values.put("tradeBatchCode","");
								values.put("orderCode",getIntent().getStringExtra("orderCode"));

								boolean flag = YourApplication.orderDatabaseHelper.insertData(values);


								netRequest.startRequest(RequestUrls.hostUrl + RequestUrls.posPayOrderSuccess,
										Method.POST,
										NetParams.posPayOrderSuccess(mContext, orderId, 0, payType, payBillNumber,
												dealTime, payAmount, 0, 0, memberPayToken, secondPayNumber, "", "", "",
												"", "", "", "", "",getIntent().getStringExtra("orderCode")),
										0, listener);
							} else {
								secondPayNumber = result.optString(PayContacts.REFERENCE_NO);
								String merCode = result.optString(PayContacts.MERCHANT_ID);
								String merName = result.optString(PayContacts.MERCHANT_NAME);
								String termCode = result.optString(PayContacts.TERMINAL_ID);
								String bankName = result.optString(PayContacts.BANK_CODE_ID);
								String bankCard = result.optString(PayContacts.CARD_NUMBER);
								String bankCardExpired = result.optString(PayContacts.CARD_VALIDITY);
								String authorCode = result.optString(PayContacts.AUTHORIZATION_NUMBER);
								String tradeBatchCode = result.optString(PayContacts.BATCH_NUMBER);
								netRequest.startRequest(RequestUrls.hostUrl + RequestUrls.posPayOrderSuccess,
										Method.POST,
										NetParams.posPayOrderSuccess(mContext, orderId, 0, payType, payBillNumber,
												dealTime, payAmount, 0, 0, memberPayToken, secondPayNumber, merCode,
												merName, termCode, bankName, bankCard, bankCardExpired, authorCode,
												tradeBatchCode,getIntent().getStringExtra("orderCode")),
										0, listener);
								ContentValues values = new ContentValues();
								values.put("id",orderId);
								values.put("payStatus","0");
								values.put("payMethod",payType+"");
								values.put("payBillNumber",payBillNumber);
								values.put("payDate",dealTime);
								values.put("payAmount",payAmount);
								values.put("cashAmount","0");
								values.put("cashChange","0");
								values.put("memberPayToken",memberPayToken);
								values.put("secondPayNumber",secondPayNumber);
								values.put("merCode",merCode);
								values.put("merName",merName);
								values.put("termCode",termCode);
								values.put("bankName",bankName);
								values.put("bankCard",bankCard);
								values.put("bankCardExpired",bankCardExpired);
								values.put("authorCode",authorCode);
								values.put("tradeBatchCode",tradeBatchCode);
								values.put("orderCode",getIntent().getStringExtra("orderCode"));
								boolean flag = YourApplication.orderDatabaseHelper.insertData(values);
							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}

				}
				// {"trade_type":"015,"merchantName":"","merchantId":"900491555410000",
				// "terminalId":
				// "01608074","amount":"000000000001","voucherNo":"1508918150646235014","servera
				// uditnumber":"10021015089181553839221", "pay_way_wa":"翼支付",
				// "dealTime":"2017-10-25 15:56:05"}

			} else if (resultCode == RESULT_CANCELED) {
				if (data != null) {
					String errorInfo = data.getStringExtra(PayContacts.RETURN_DATA);
					showShortToast("支付失败:" + errorInfo);
				} else {
					showShortToast("支付失败");
				}
			}
		}









	/*	if (requestCode == 0) {
			if (resultCode == RESULT_OK) {
				setResult(RESULT_OK);
				finish();
			}
		} else if (requestCode == 100) {
			if (resultCode == RESULT_OK) {
				if (data != null) {
					Log.e("TAG", "onActivityResult: "+ data.getStringExtra(PayContacts.RETURN_DATA) );
					String dealData = data.getStringExtra(PayContacts.RETURN_DATA);
					if (!TextUtils.isEmpty(dealData)) {
						JSONObject result;
						try {
							result = new JSONObject(dealData);
							String payBillNumber = result.optString("voucherNo");
							long payAmount = result.optLong("amount", 0);
							String dealTime = result.optString("dealTime");
							String secondPayNumber = "";
							if (payType != 4) {
								secondPayNumber = result.optString(PayContacts.SERVERAUDITNUMBER);
								ContentValues values = new ContentValues();
								values.put("id",orderId);
								values.put("payStatus","0");
								values.put("payMethod",payType+"");
								values.put("payBillNumber",payBillNumber);
								values.put("payDate",dealTime);
								values.put("payAmount",payAmount);
								values.put("cashAmount","0");
								values.put("cashChange","0");
								values.put("memberPayToken",memberPayToken);
								values.put("secondPayNumber",secondPayNumber);
								values.put("merCode","");
								values.put("merName","");
								values.put("termCode","");
								values.put("bankName","");
								values.put("bankCard","");
								values.put("bankCardExpired","");

								values.put("authorCode","");
								values.put("tradeBatchCode","");
								values.put("orderCode",getIntent().getStringExtra("orderCode"));

								boolean flag = YourApplication.orderDatabaseHelper.insertData(values);

							//	startPrintAndOut(payType,dealTime,payBillNumber,"","","","","","","");
                                startPrint(payType,dealTime,payBillNumber,"","","","","","","");
							netRequest.startRequest(RequestUrls.hostUrl + RequestUrls.posPayOrderSuccess,
										Method.POST,
										NetParams.posPayOrderSuccess(mContext, orderId, 0, payType, payBillNumber,
												dealTime, payAmount, 0, 0, memberPayToken, secondPayNumber, "", "", "",
												"", "", "", "", "",getIntent().getStringExtra("orderCode")),
										0, listener);
							} else {
								secondPayNumber = result.optString(PayContacts.REFERENCE_NO);
								String merCode = result.optString(PayContacts.MERCHANT_ID);
								String merName = result.optString(PayContacts.MERCHANT_NAME);
								String termCode = result.optString(PayContacts.TERMINAL_ID);
								String bankName = result.optString(PayContacts.BANK_CODE_ID);
								String bankCard = result.optString(PayContacts.CARD_NUMBER);
								String bankCardExpired = result.optString(PayContacts.CARD_VALIDITY);
								String authorCode = result.optString(PayContacts.AUTHORIZATION_NUMBER);
								String tradeBatchCode = result.optString(PayContacts.BATCH_NUMBER);
								startPrint(payType,dealTime,payBillNumber,sn,termCode,merCode,bankCard,result.optString("voucherNo"),authorCode,secondPayNumber);
								netRequest.startRequest(RequestUrls.hostUrl + RequestUrls.posPayOrderSuccess,
										Method.POST,
										NetParams.posPayOrderSuccess(mContext, orderId, 0, payType, payBillNumber,
												dealTime, payAmount, 0, 0, memberPayToken, secondPayNumber, merCode,
												merName, termCode, bankName, bankCard, bankCardExpired, authorCode,
												tradeBatchCode,getIntent().getStringExtra("orderCode")),
										0, listener);
								ContentValues values = new ContentValues();
								values.put("id",orderId);
								values.put("payStatus","0");
								values.put("payMethod",payType+"");
								values.put("payBillNumber",payBillNumber);
								values.put("payDate",dealTime);
								values.put("payAmount",payAmount);
								values.put("cashAmount","0");
								values.put("cashChange","0");
								values.put("memberPayToken",memberPayToken);
								values.put("secondPayNumber",secondPayNumber);
								values.put("merCode",merCode);
								values.put("merName",merName);
								values.put("termCode",termCode);
								values.put("bankName",bankName);
								values.put("bankCard",bankCard);
								values.put("bankCardExpired",bankCardExpired);
								values.put("authorCode",authorCode);
								values.put("tradeBatchCode",tradeBatchCode);
								values.put("orderCode",getIntent().getStringExtra("orderCode"));
								boolean flag = YourApplication.orderDatabaseHelper.insertData(values);

							}

						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}

				}
				// {"trade_type":"015,"merchantName":"","merchantId":"900491555410000",
				// "terminalId":
				// "01608074","amount":"000000000001","voucherNo":"1508918150646235014","servera
				// uditnumber":"10021015089181553839221", "pay_way_wa":"翼支付",
				// "dealTime":"2017-10-25 15:56:05"}

			} else if (resultCode == RESULT_CANCELED) {
				if (data != null) {
					String errorInfo = data.getStringExtra(PayContacts.RETURN_DATA);
					showShortToast("支付失败:" + errorInfo);
				} else {
					showShortToast("支付失败");
				}
			}
		}*/
	}

	@Override
	public void initView() {
		setContentView(R.layout.account_layout);
		button_back = bindId(R.id.button_back);
		button_weixin = bindId(R.id.button_weixin);
		button_zhifubao = bindId(R.id.button_zhifubao);
		button_yizhifu = bindId(R.id.button_yizhifu);
		button_shuaka = bindId(R.id.button_shuaka);
		listView = bindId(R.id.listView);
		text_total = bindId(R.id.text_total);
		text_totalPrice = bindId(R.id.text_totalPrice);
		text_finalPrice = bindId(R.id.text_finalPrice);
		text_discountPrice = bindId(R.id.text_discountPrice);
		text_memberCode = bindId(R.id.text_memberCode);
		text_levelName = bindId(R.id.text_levelName);
		text_memberBalance = bindId(R.id.text_memberBalance);
		text_memberScore = bindId(R.id.text_memberScore);
		linear_member = bindId(R.id.linear_member);

	}

	@Override
	public void initData() {
		AppSet.cashierActivities.add(this);
		userBean = (UserBean) FilesManager.readObject(mContext, FilesManager.User);
		gson = new Gson();
		ActionBarManager.init(this, "收银台-支付", true, "现金收款", new OnClickListener() {

			@Override
			public void onClick(View v) {
			//	startPrintAndOut(0,Tools.stampToDate(System.currentTimeMillis() + ""),"","","","","","","","");
                startPrint(0,Tools.stampToDate(System.currentTimeMillis() + ""),"",android.os.Build.SERIAL,"","","","","","");
				netRequest.startRequest(RequestUrls.hostUrl + RequestUrls.posPayOrderSuccess, Method.POST,
						NetParams.posPayOrderSuccess(mContext, orderId, 0, 0, "",
								Tools.stampToDate(System.currentTimeMillis() + ""), 0, finalPrice, 0, memberPayToken,
								"", "", "", "", "", "", "", "", "",getIntent().getStringExtra("orderCode")),
						0, listener);

			}
		});
		orderId = getIntent().getStringExtra("orderId");
		memberPayToken = getIntent().getStringExtra("memberPayToken");
		finalPrice = getIntent().getLongExtra("finalPrice", 0);
		isFastCashier = getIntent().getBooleanExtra("isFastCashier", false);
		if (isFastCashier) {
			button_back.setText("返回到快速收银");
			listView.setVisibility(View.GONE);
			linear_member.setVisibility(View.GONE);
			text_total.setText("1");
			text_totalPrice.setText(FinancialUtils.fenToYuan(finalPrice));
			text_finalPrice.setText(FinancialUtils.fenToYuan(finalPrice));
			text_discountPrice.setText("0");
		} else {

			goods = getIntent().getStringExtra("goods");
			memberCode = getIntent().getStringExtra("memberCode");
			memberBalance = getIntent().getStringExtra("memberBalance");
			levelName = getIntent().getStringExtra("levelName");
			memberScore = getIntent().getStringExtra("memberScore");
			totalPrice = getIntent().getLongExtra("totalPrice", 0);
			discountPrice = getIntent().getLongExtra("discountPrice", 0);
			if (TextUtils.isEmpty(memberCode)) {
				linear_member.setVisibility(View.GONE);
			} else {
				linear_member.setVisibility(View.VISIBLE);
			}
			if (TextUtils.isEmpty(memberBalance)) {
				memberBalance = "-";
			}
			if (TextUtils.isEmpty(levelName)) {
				levelName = "-";
			}
			if (TextUtils.isEmpty(memberScore)) {
				memberScore = "-";
			}
			goodsList = gson.fromJson(goods, new TypeToken<List<AccountGoodsBean>>() {
			}.getType());
			adapter = new AccountGoodsListAdapter(mContext, goodsList);
			listView.setAdapter(adapter);
			int totalNum = 0;
			for (AccountGoodsBean item : goodsList) {
				totalNum = totalNum + item.getGoodsCount();
			}
			text_total.setText(totalNum + "");
			text_totalPrice.setText(FinancialUtils.fenToYuan(totalPrice));
			text_finalPrice.setText(FinancialUtils.fenToYuan(finalPrice));
			text_discountPrice.setText(FinancialUtils.fenToYuan(discountPrice));
			text_memberCode.setText(memberCode);
			text_levelName.setText(levelName);
			text_memberBalance.setText(memberBalance);
			text_memberScore.setText(memberScore);
			for (int n=0;n<goodsList.size();n++){
				goodinfo=goodinfo+"\n"+goodsList.get(n).getGoodsName()+"    "+"数量:"+goodsList.get(n).getGoodsCount()+"   "+"单价:"+FinancialUtils.fenToYuan(goodsList.get(n).getGoodsPrice()) ;
			}
		}
	}

	@Override
	public void initListener() {
		button_back.setOnClickListener(this);
		button_weixin.setOnClickListener(this);
		button_zhifubao.setOnClickListener(this);
		button_yizhifu.setOnClickListener(this);
		button_shuaka.setOnClickListener(this);

	}

	private BaseRequestListener listener = new JsonRequestListener() {

		@Override
		public void onStart(int requestId) {
			showDialg();
		}

		@Override
		public void onError(int requestId, int errorCode, String errorMsg) {
			disMissDialog();
			dealError(errorCode, errorMsg);
		}

		@Override
		public void onSuccess(int requestId, String url, JSONObject jsonResult) {
			Log.e("TAG", "onSuccess: "+jsonResult.toString() );
			disMissDialog();
			int retCode = jsonResult.optInt("retCode", 0);

			if (requestId == 0) {
				if (retCode == 1) {
					showShortToast("无此订单");
					return;
				}
				if (retCode == 2) {
					showShortToast("会员token校验失败");
					return;
				}
				if (retCode == 3) {
					showShortToast("订单校验失败");
					return;
				}
				String memberCode = jsonResult.optString("memberCode");
				String memberName = jsonResult.optString("memberName");
				String memberLevel = jsonResult.optString("memberLevel");
				String memberScore = jsonResult.optString("memberScore");
				String menberBalance = jsonResult.optString("menberBalance");
				String printInfo = jsonResult.optString("printInfo");

				Intent intent = new Intent(mContext, PaySuccessActivity.class);
				intent.putExtra("memberCode", memberCode);
				intent.putExtra("memberName", memberName);
				intent.putExtra("memberLevel", memberLevel);
				intent.putExtra("memberScore", memberScore);
				intent.putExtra("printInfo", printInfo);
				intent.putExtra("totalPrice", finalPrice);
				intent.putExtra("payBillNumber",jsonResult.optString("orderCode"));
				startActivityForResult(intent, 0);
			}

		}
	};

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.button_back:
			finish();
			break;
//		case R.id.button_cash:
//			Log.e("TAG", "onClick: "+"22222222222222" );
//			netRequest.startRequest(RequestUrls.hostUrl + RequestUrls.posPayOrderSuccess, Method.POST,
//					NetParams.posPayOrderSuccess(mContext, orderId, 0, 0, "",
//							Tools.stampToDate(System.currentTimeMillis() + ""), 0, finalPrice, 0, memberPayToken, "",
//							"", "", "", "", "", "", "", "",getIntent().getStringExtra("orderCode")),
//					0, listener);
//
//
//			break;
		case R.id.button_weixin:
			payType = 1;
			merId = userBean.getWeixinMerCode();
			tstTypeId = "WX";
			startPay();
			break;
		case R.id.button_zhifubao:
			payType = 2;
			merId = userBean.getAlipayMerCode();
			tstTypeId = "ALI";
			startPay();
			break;
		case R.id.button_yizhifu:
			payType = 3;
			merId = userBean.getBestPayCode();
//			tstTypeId = "YZF";
			tstTypeId = "EPAY";
			startPay();
			break;
		case R.id.button_shuaka:

			payType = 4;
			merId = userBean.getBestPayCode();
//			tstTypeId = "YZF";
			tstTypeId = "UNIONPAY";
			// Toast.makeText(mContext, "暂未开通该功能", Toast.LENGTH_SHORT).show();
			startPay();
//			payType = 4;
//			startPay();
			break;

		default:
			break;
		}

	}

	private void startPay() {
		Intent intent = new Intent(mContext, ScannerPayActivity2.class);
		intent.putExtra("payType", payType);
		intent.putExtra("merId", merId);
		intent.putExtra("tstTypeId", tstTypeId);
		intent.putExtra("amount", FinancialUtils.fenToYuan(finalPrice));
		intent.putExtra("threeOrdNum", orderId);
		intent.putExtra("memberPayToken", memberPayToken);
		intent.putExtra("orderCode", getIntent().getStringExtra("orderCode"));
		intent.putExtra("goodInfo",goodinfo);
		intent.putExtra("finalprice",finalPrice);
		intent.putExtra("discountprice",discountPrice);
		startActivityForResult(intent, 11);

	/*	JSONObject object = new JSONObject();
		try {
			switch (payType) {
			case 1:
				object.put(PayContacts.TRADE_TYPE, PayContacts.WECHAT_PAY_TYPE);
				object.put(PayContacts.AMOUNT, finalPrice + "");
				object.put(PayContacts.EXTERNAL_MERCHANT_NO, userBean.getWeixinMerCode());

				break;
			case 2:
				object.put(PayContacts.TRADE_TYPE, PayContacts.ALIPAY_PAY_TYPE);
				object.put(PayContacts.AMOUNT, finalPrice + "");
				object.put(PayContacts.EXTERNAL_MERCHANT_NO, userBean.getAlipayMerCode());

				break;
			case 3:
				object.put(PayContacts.TRADE_TYPE, "015");
				object.put(PayContacts.AMOUNT, finalPrice + "");
				object.put(PayContacts.EXTERNAL_MERCHANT_NO, userBean.getBestPayCode());
				Log.e("TAG", "startPay: "+userBean.getBestPayCode() );

				break;
			case 4:
				object.put(PayContacts.TRADE_TYPE, PayContacts.SALE_TYPE);
				object.put(PayContacts.AMOUNT, finalPrice + "");
				object.put(PayContacts.IS_PRINTSALESSLIP, "0");

				break;

			default:
				break;
			}
			object.put("external_serial_number", orderId);

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Intent intent = new Intent();
		intent.setAction("cn.zng.pay.action");
		intent.addCategory("cn.zng.pay.category");
		intent.putExtra(PayContacts.REQUEST_DATA, object.toString());
        Log.e("TAG", "startPay: "+object.toString() );
		startActivityForResult(intent, 100);*/
	}
	//{"trade_type":"001","merchantName":"陕西之间贸易有限公司","merchantId":"928791156990000","terminalId":"20484812","bankCodeId":"平安银行","cardNo":"6251530025376392","cardValidity":"2511","batchNo":"000001","referenceNo":"105227000033","amount":"000000000001","voucherNo":"000064","authorizationNo":"717081","dealTime":"2018-05-05 10:52:27"}
	/*private void startPrintAndOut(final int type, final String dealTime, final String payBillNumber, final String termCode, final String terminalId, final String merchantId, final String cardNo, final String voucherNo, final String authorizationNo, final String referenceNo) {

		Log.e("TAG", "startPrintAndOut: "+"111111111111111111111" );

					PrintPowerOnAndOffUtils pp = new PrintPowerOnAndOffUtils(mContext);
		pp.powerOn();
		new Handler().postDelayed(new Runnable() {
			public void run() {

				new Thread(new Runnable() {
					@Override
					public void run() {
						PrintUtils printUtils = new PrintUtils(mContext);
						printUtils.detectionPrinter();
						if(type==4){
							if(goodsList.size()==0){
								printUtils.printTextAndNewLine("　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端编号："+terminalId+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：刷卡支付\n终端号："+terminalId+"\n商户号："+merchantId+"\n卡号："+cardNo+"\n卡类型：贷记卡批次号：000001\n凭证号："+voucherNo+"\n授权号："+authorizationNo+"\n参考号："+referenceNo+"\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端编号："+terminalId+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：刷卡支付\n终端号："+terminalId+"\n商户号："+merchantId+"\n卡号："+cardNo+"\n卡类型：贷记卡批次号：000001\n凭证号："+voucherNo+"\n授权号："+authorizationNo+"\n参考号："+referenceNo+"\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n");

							}else{
								printUtils.printTextAndNewLine("　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端编号："+terminalId+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：刷卡支付\n终端号："+terminalId+"\n商户号："+merchantId+"\n卡号："+cardNo+"\n卡类型：贷记卡批次号：000001\n凭证号："+voucherNo+"\n授权号："+authorizationNo+"\n参考号："+referenceNo+goodinfo+"\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端编号："+terminalId+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：刷卡支付\n终端号："+terminalId+"\n商户号："+merchantId+"\n卡号："+cardNo+"\n卡类型：贷记卡批次号：000001\n凭证号："+voucherNo+"\n授权号："+authorizationNo+"\n参考号："+referenceNo+goodinfo+"\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n");

							}

						}else if(type==1){
							if(goodsList.size()==0){
								printUtils.printTextAndNewLine("　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：微信支付\n综合支付流水号：\n"+payBillNumber+"\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：微信支付\n综合支付流水号：\n"+payBillNumber+"\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n");

							}else{
								printUtils.printTextAndNewLine("　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：微信支付\n综合支付流水号：\n"+payBillNumber+goodinfo+"\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：微信支付\n综合支付流水号：\n"+payBillNumber+goodinfo+"\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n");

							}


						}else if(type==2){
							if(goodsList.size()==0){
								printUtils.printTextAndNewLine("　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：支付宝支付\n综合支付流水号：\n"+payBillNumber+"\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：支付宝支付\n综合支付流水号：\n"+payBillNumber+"\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n");

							}else{
								printUtils.printTextAndNewLine("　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：支付宝支付\n综合支付流水号：\n"+payBillNumber+goodinfo+"\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：支付宝支付\n综合支付流水号：\n"+payBillNumber+goodinfo+"\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n");

							}

						}else if(type==3){
							if(goodsList.size()==0){
								printUtils.printTextAndNewLine("　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：翼支付\n综合支付流水号：\n"+payBillNumber+"\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：翼支付\n综合支付流水号：\n"+payBillNumber+"\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n");

							}else{
								printUtils.printTextAndNewLine("　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：翼支付\n综合支付流水号：\n"+payBillNumber+goodinfo+"\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n终端sn号："+termCode+"\n交易号: "+getIntent().getStringExtra("orderCode")+"\n交易时间:"+dealTime+"\n应收："+totalPrice+"\n实收："+finalPrice+"\n折让: "+discountPrice+"\n支付方式：翼支付\n综合支付流水号：\n"+payBillNumber+goodinfo+"\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n");

							}

						}else if(type==0) {
							if(goodsList.size()==0){
								printUtils.printTextAndNewLine(" 　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + totalPrice + "\n实收：" + finalPrice + "\n折让: " + discountPrice + "\n支付方式：现金支付\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：自坚零售\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + totalPrice + "\n实收：" + finalPrice + "\n折让: " + discountPrice + "\n支付方式：现金支付\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n");

							}else{
								printUtils.printTextAndNewLine(" 　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + totalPrice + "\n实收：" + finalPrice + "\n折让: " + discountPrice +goodinfo+ "\n支付方式：现金支付\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：自坚零售\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + totalPrice + "\n实收：" + finalPrice + "\n折让: " + discountPrice + goodinfo+"\n支付方式：现金支付\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n\n\n\n");

							}
						}
									//打印条形码
						Log.e("TAG", "run: "+getIntent().getStringExtra("orderCode") );
						printUtils.printOneDemChar(getIntent().getStringExtra("orderCode"));
						printUtils.printStepPass(40);
						mHandler.sendEmptyMessage(0);
					}
				}).start();

			}
		}, 500);

	}
	private Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			setResult(RESULT_OK);
			finish();
		};
	};*/


	private void startPrint(final int type, final String dealTime, final String payBillNumber, final String termCode, final String terminalId, final String merchantId, final String cardNo, final String voucherNo, final String authorizationNo, final String referenceNo) {
		{

			Log.e("TAG", "startPrint: "+getIntent().getStringExtra("orderCode") );
			//	ServiceManager.getInstence().verifyData("2222222");
			try {
				try {
					JSONArray printTest = new JSONArray();

					JSONObject json0 = new JSONObject();
					json0.put("content-type", "txt");
					if (type == 4) {
						if (goodsList.size() == 0) {
							json0.put("content", "　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端编号：" + terminalId + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice) + "\n实收：" + FinancialUtils.fenToYuan(finalPrice) + "\n折让: " + discountPrice + "\n支付方式：刷卡支付\n终端号：" + terminalId + "\n商户号：" + merchantId + "\n卡号：" + cardNo + "\n卡类型：贷记卡批次号：000001\n凭证号：" + voucherNo + "\n授权号：" + authorizationNo + "\n参考号：" + referenceNo + "\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端编号：" + terminalId + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：刷卡支付\n终端号：" + terminalId + "\n商户号：" + merchantId + "\n卡号：" + cardNo + "\n卡类型：贷记卡批次号：000001\n凭证号：" + voucherNo + "\n授权号：" + authorizationNo + "\n参考号：" + referenceNo + "\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n");

						} else {
							json0.put("content", "　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端编号：" + terminalId + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice) + "\n实收：" + FinancialUtils.fenToYuan(finalPrice) + "\n折让: " + discountPrice + "\n支付方式：刷卡支付\n终端号：" + terminalId + "\n商户号：" + merchantId + "\n卡号：" + cardNo + "\n卡类型：贷记卡批次号：000001\n凭证号：" + voucherNo + "\n授权号：" + authorizationNo + "\n参考号：" + referenceNo + goodinfo + "\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端编号：" + terminalId + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：刷卡支付\n终端号：" + terminalId + "\n商户号：" + merchantId + "\n卡号：" + cardNo + "\n卡类型：贷记卡批次号：000001\n凭证号：" + voucherNo + "\n授权号：" + authorizationNo + "\n参考号：" + referenceNo + goodinfo + "\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n");

						}

					} else if (type == 1) {
						if (goodsList.size() == 0) {
							json0.put("content", "　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice) + "\n实收：" + FinancialUtils.fenToYuan(finalPrice) + "\n折让: " + discountPrice + "\n支付方式：微信支付\n综合支付流水号：\n" + payBillNumber + "\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：微信支付\n综合支付流水号：\n" + payBillNumber + "\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n");

						} else {
							json0.put("content", "　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice) + "\n实收：" +  FinancialUtils.fenToYuan(finalPrice) + "\n折让: " + discountPrice + "\n支付方式：微信支付\n综合支付流水号：\n" + payBillNumber + goodinfo + "\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：微信支付\n综合支付流水号：\n" + payBillNumber + goodinfo + "\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n");


						}


					} else if (type == 2) {
						if (goodsList.size() == 0) {
							json0.put("content", "　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice) + "\n实收：" + FinancialUtils.fenToYuan(finalPrice) + "\n折让: " + discountPrice + "\n支付方式：支付宝支付\n综合支付流水号：\n" + payBillNumber + "\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：支付宝支付\n综合支付流水号：\n" + payBillNumber + "\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n");

						} else {
							json0.put("content", "　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice) + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：支付宝支付\n综合支付流水号：\n" + payBillNumber + goodinfo + "\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：支付宝支付\n综合支付流水号：\n" + payBillNumber + goodinfo + "\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n");

						}

					} else if (type == 3) {
						if (goodsList.size() == 0) {
							json0.put("content", "　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice) + "\n实收：" + FinancialUtils.fenToYuan(finalPrice) + "\n折让: " + discountPrice + "\n支付方式：翼支付\n综合支付流水号：\n" + payBillNumber + "\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：翼支付\n综合支付流水号：\n" + payBillNumber + "\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n");

						} else {
							json0.put("content", "　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice) + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：翼支付\n综合支付流水号：\n" + payBillNumber + goodinfo + "\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n终端sn号：" + termCode + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：翼支付\n综合支付流水号：\n" + payBillNumber + goodinfo + "\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n");

						}

					} else if (type == 0) {
						if (goodsList.size() == 0) {
							json0.put("content", " 　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" +  FinancialUtils.fenToYuan(finalPrice) + "\n实收：" +  FinancialUtils.fenToYuan(finalPrice) + "\n折让: " + discountPrice + "\n支付方式：现金支付\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + "\n支付方式：现金支付\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n");

						} else {
							json0.put("content", " 　　　　POS 签购单\n　　　　　（消费单）\n商户名称：" + userBean.getStoreName() + "\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" +  FinancialUtils.fenToYuan(finalPrice) + "\n实收：" + FinancialUtils.fenToYuan(finalPrice) + "\n折让: " + discountPrice + goodinfo + "\n支付方式：现金支付\n--------------------------------\n\n========商户存根=========\n　　　　POS 签购单\n　　　　　（消费单）\n商户名称："+userBean.getStoreName()+"\n交易号: " + getIntent().getStringExtra("orderCode") + "\n交易时间:" + dealTime + "\n应收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n实收：" + FinancialUtils.fenToYuan(finalPrice)  + "\n折让: " + discountPrice + goodinfo + "\n支付方式：现金支付\n--------------------------------\n\n\n\n持卡人签名：\n\n\n\n\n\n\n");

						}
					}

					//	json0.put("content", "212123123");
					json0.put("size", "2");
					json0.put("position", "left");
					json0.put("offset", "0");
					json0.put("bold", "0");
					json0.put("italic", "0");
					json0.put("height", "-1");
					JSONObject json1 = new JSONObject();
					json1.put("content-type", "one-dimension");
					json1.put("content", getIntent().getStringExtra("orderCode"));
					json1.put("size", "3");
					json1.put("position", "left");
					json1.put("offset", "0");
					json1.put("bold", "0");
					json1.put("italic", "0");
					json1.put("height", "-1");
					printTest.put(json0);
					printTest.put(json1);
					printJson.put("spos", printTest);
					// 设置底部空3行
					// Set at the bottom of the empty 3 rows
					com.pos.sdk.printer.PosPrinter.Parameters parameters = ServiceManager.getInstence().getPrinter()
							.getParameters();
					parameters.setPrintGray(5000);
					parameters.setPrintStep(4000);
					parameters.setPrintHeatPoint(1000);
					ServiceManager.getInstence().getPrinter().setParameters(parameters);
					ServiceManager.getInstence().getPrinter().setPrintGray(2000);
					ServiceManager.getInstence().getPrinter().printBottomFeedLine(5);
					ServiceManager.getInstence().getPrinter().print(printJson.toString(), null, printer_callback);
				/*JSONObject jsonObject=new JSONObject();
				JSONArray printTest1 = new JSONArray();

				JSONObject json01 = new JSONObject();
				json0.put("content-type", "one-dimension");
				json0.put("content", "11123123");
				json0.put("size", "2");
				json0.put("position", "left");
				json0.put("offset", "0");
				json0.put("bold", "0");
				json0.put("italic", "0");
				json0.put("height", "-1");
				jsonObject.put("spos", printTest1);
				ServiceManager.getInstence().getPrinter().print(jsonObject.toString(), null, printer_callback);*/
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}
}
